﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace TeXTable
{
	/// <summary>
	/// The application is aimed at autoamtic construction of table rows in the LaTeX format provided raw data.
	/// Results are written into the standard output stream.
	/// </summary>
	class Program
	{
		static void Main(string[] args)
		{
			if (args.Length < 1)
			{
				Console.WriteLine("Please specify input file.");
				return;
			}

			const char defSep = '\t';
			const string colSep = @"&";
			const string endl = @"\\";
			const string outfile = @"tex";
			const string hline = @"\hline";
			var file = args[0];
			var lines = File.ReadAllLines(file);
			using (var writer = new StreamWriter(outfile))
			{
				foreach (var line in lines)
				{
					var cols = line.Split(defSep);
					var row = cols[0];
					for (int i = 1; i < cols.Length; i++)
					{
						if (string.IsNullOrEmpty(cols[i])) continue;

						row += "\t" + colSep + cols[i];
					}
					row += endl;
					writer.WriteLine(row);
					writer.WriteLine(hline);
				}
			}
		}
	}
}
